package g

import (
	"goetl/core"
	"goetl/models"
	"goetl/services"
	"goetl/utils"
)

const DESIGN_FOLDER_NAME string = "<Design Time>"

//agent管理
type AgentManager struct {
	engines map[string]*core.AgentRuntime
	agents  []*models.Agent
}

func (this *AgentManager) Start() {

	//初始化engines
	this.engines = make(map[string]*core.AgentRuntime)

	_, this.agents = services.OperationsService.FindAgents()

	for i := range this.agents {
		a := *this.agents[i]
		utils.ConsoleLogs.Info("-----\nStart Agent Runtime %s \n-------", a.Name)

		this.CreateAndStartRuntime(a)

	}
}

func (this *AgentManager) CreateAndStartRuntime(agent models.Agent) core.AgentRuntime {

	engine := core.NewAgentRuntime(agent)

	this.engines[agent.Id] = engine
	go engine.Start()
	return *engine
}

func (this *AgentManager) GetAvailableAgents() []*models.Agent {
	return this.agents
}

func (this *AgentManager) GetAgentRuntime(agentId string) *core.AgentRuntime {

	return this.engines[agentId]
}
